home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / SAMPLE3.SQL < prev    next >
Encoding:
Text File  |  1995-05-18  |  1.3 KB  |  49 lines

  1. rem 
  2. rem $Header: sample3.sql 7020100.1 94/09/28 16:39:48 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      sample3.sql - <one-line expansion of the name>
  7. Rem    DESCRIPTION
  8. Rem      <short description of component this file declares/defines>
  9. Rem    RETURNS
  10. Rem 
  11. Rem    NOTES
  12. Rem      <other useful comments, qualifications, etc.>
  13. Rem    MODIFIED   (MM/DD/YY)
  14. Rem     rvasired   05/12/92 -  Creation 
  15. /*
  16. ** This example illustrates block structure and scope rules.  An
  17. ** outer block declares two variables named X and COUNTER, and loops four
  18. ** times.  Inside the loop is a sub-block that also declares a variable
  19. ** named X.  The values inserted into the TEMP table show that the two
  20. ** X's are indeed different.
  21. **
  22. ** Copyright (c) 1989,1992 by Oracle Corporation
  23. */
  24.  
  25. DECLARE
  26.     x        NUMBER := 0;
  27.     counter  NUMBER := 0;
  28. BEGIN
  29.     FOR i IN 1..4 LOOP
  30.     x := x + 1000;
  31.     counter := counter + 1;
  32.         INSERT INTO temp VALUES (x, counter, 'in OUTER loop');
  33.  
  34.     /* start an inner block */
  35.         DECLARE
  36.         x  NUMBER := 0;   -- this is a local version of x
  37.     BEGIN
  38.         FOR i IN 1..4 LOOP
  39.         x := x + 1;   -- this increments the local x
  40.         counter := counter + 1;
  41.             INSERT INTO temp VALUES (x, counter, 'inner loop');
  42.         END LOOP;
  43.     END;
  44.  
  45.     END LOOP;
  46.     COMMIT;
  47. END;
  48. /
  49.